<?php
apf_require_controller('Oa_Attendance_Abstract');
apf_require_class('Tools_Uploader');

class Oa_Attendance_AjaxUploadController extends Oa_Attendance_AbstractController {


    public function handle_request() {
        #print_r($_FILES);exit;
        $upDir = 'upload/attendance';
        $is_up = false;
        if($_FILES['file']['tmp_name']) {
            $is_up = true;
            $uploader = new Tools_Uploader('file');
            $uploader->setValidExt(array(
                    '.jpg',
                    '.gif'
            ));
            $uploader->setUpDir(CODE_PATH . $upDir); // 需修改为你自己的路径
            $error = array();
            if($uploader->upload()) {
                $res = $uploader->getFileName();
                $res = "/upload/attendance/".$res;
                $txt = "<script type='text/javascript'>window.parent.document.getElementById('need_img').setAttribute('src','$res');";
                $txt .= "window.parent.document.getElementById('need_img_a').setAttribute('href','$res');";
                $txt .= "window.parent.document.getElementById('img_file').setAttribute('value','$res');";
                $txt .= "window.parent.document.getElementById('need_img_li').style.display='block';";
                $txt .= "</script>";
            } else {
                $res = $uploader->getErrorMsg();
                $txt = "<script type='text/javascript'>alert('$res');</script>";
            }
            echo $txt;exit;

        }
    }
}